<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>clientWidth&Height</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }

        .box{
            position: absolute;
            top: 50px;
            left: 50px;
            width: 150px;
            height: 150px;
            background-color: #f00;
        }

        .inner {
            width: 400px;
            height: 400px;
        }
    </style>
</head>
<body>
    <!-- Client：
        Width/Height: 显示元素内容可视大小。元素自身宽高 + padding，有滚动条时，会减去滚动条的宽度
        Top/Left：返回元素上左边框的宽度
        只读的整数
    -->

    <div class="box"></div>

    <script type="text/javascript">
        var box = document.querySelector(".box");    

        console.log("box.clientWidth", box.clientWidth, "\nbox.clientHeight", box.clientHeight); // 150 150
        
        box.style.padding = "30px";
        console.log("add padding 30");
        console.log("box.clientWidth", box.clientWidth, "\nbox.clientHeight", box.clientHeight); // 210 210

        box.style.border = "30px solid #00f";
        console.log("add border 30");
        console.log("box.clientWidth", box.clientWidth, "\nbox.clientHeight", box.clientHeight); // 210 210


        box.innerHTML = "<div class='inner'></div>";
        console.log("内容溢出");
        console.log("box.clientWidth", box.clientWidth, "\nbox.clientHeight", box.clientHeight); // 210 210
        
        box.style.overflow = "scroll";
        console.log("出现滚动条");
        console.log("box.clientWidth", box.clientWidth, "\nbox.clientHeight", box.clientHeight); // 193 193
        
        box.clientWidth = "300";
        console.log("设置clientWidth 300");
        console.log("box.clientWidth", box.clientWidth, "\nbox.clientHeight", box.clientHeight); // 193 193
        
        box.style.width = "150.333px";
        console.log("设置width为小数");
        console.log("box.clientWidth", box.clientWidth, "\nbox.clientHeight", box.clientHeight); // 193 193
    </script>
</body>
</html>